package com.weiyirong99.crm.app.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.weiyirong99.crm.app.R;
import com.weiyirong99.crm.app.bean.PhoneListBean;

import java.util.List;

public class PhoneAdapter extends BaseQuickAdapter<PhoneListBean.ListDTO, BaseViewHolder> {

    public PhoneAdapter(int layoutResId, @Nullable List<PhoneListBean.ListDTO> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, PhoneListBean.ListDTO listDTO) {
        TextView phone = (TextView) baseViewHolder.findView(R.id.phone);
        phone.setText(dealPhoneNumber(listDTO.getMobile()));
        TextView name = (TextView) baseViewHolder.findView(R.id.name);
        name.setText(listDTO.getName());
        ImageView iv = (ImageView) baseViewHolder.findView(R.id.iv_img);
        RatingBar tvstar =(RatingBar)baseViewHolder.findView(R.id.tvstar);
        tvstar.setNumStars(5);
        tvstar.setRating(listDTO.getStar());
//        switch (listDTO.getStar()) {
//            case 0:
//                iv.setImageResource(R.drawable.img06);
//                break;
//            case 1:
//                iv.setImageResource(R.drawable.img05);
//                break;
//            case 2:
//                iv.setImageResource(R.drawable.img04);
//                break;
//            case 3:
//                iv.setImageResource(R.drawable.img03);
//                break;
//            case 4:
//                iv.setImageResource(R.drawable.img02);
//                break;
//            case 5:
//                iv.setImageResource(R.drawable.img01);
//                break;
//
//        }
//        public enum CustomerStateEnum {
//            UNKNOWN(0, "未知"),
//            WAIT_FOLLOW_UP(1, "待跟进"),
//            UNQUALIFIED(2, "资质不符合"),
//            WAIT_SIGN(3, "待签约"),
//            SIGNED(4, "已签约"),
//            VISITED(5, "已上门"),
//            APPROVAL(6, "审核中"),
//            LOAN(7, "已放款"),
//            EXAMINING(8, "在审件"),
//            INVALID(9, "捣乱申请"),
//            BLACK_LIST(10, "黑名单")
//            ;
//
//            CustomerStateEnum(int i, String desc) {
//
//            }
//        }
        TextView type = (TextView) baseViewHolder.findView(R.id.item_type);
        switch (listDTO.getState()) {
            case "UNKNOWN":
                type.setText("未知");
                break;
            case "WAIT_FOLLOW_UP":
                type.setText("待跟进");
                break;
            case "UNQUALIFIED":
                type.setText("资质不符合");
                break;
            case "WAIT_SIGN":
                type.setText("待签约");
                break;
            case "SIGNED":
                type.setText("已签约");
                break;
            case "VISITED":
                type.setText("已上门");
                break;
            case "APPROVAL":
                type.setText("审核中");
                break;
            case "LOAN":
                type.setText("已放款");
                break;
            case "EXAMINING":
                type.setText("在审件");
                break;
            case "INVALID":
                type.setText("捣乱申请");
                break;
            case "BLACK_LIST":
                type.setText("黑名单");
                break;
        }
    }

    private String dealPhoneNumber(String phoneNumber) {
        if (!TextUtils.isEmpty(phoneNumber)) {
            int len = phoneNumber.length();
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < len; i++) {
                if (i > 2 && i < 7) {
                    builder.append("*");
                } else {
                    builder.append(phoneNumber.charAt(i));
                }

                if (i == 2 || i == 6) {
                    if (i != len - 1)
                        builder.append(" ");
                }
            }

            return builder.toString();
        }
        return null;
    }
}
